package com.soft.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.soft.entity.Sushe;
import com.soft.entity.Person;
import com.soft.mapper.SusheMapper;
import com.soft.mapper.PersonMapper;

@Service
public class PersonService {
    @Autowired
    private SusheMapper susheMapper;
    @Autowired
    private PersonMapper personMapper;
    public List<Person> queryBySusheSno(String SusheFloor) {
        QueryWrapper<Sushe> susheWrapper = new QueryWrapper<>();
        susheWrapper.eq("sushe_floor", SusheFloor);
        Sushe sushe = susheMapper.selectOne(susheWrapper);

        QueryWrapper<Person> personWrapper = new QueryWrapper<>();
        personWrapper.eq("person_sno", sushe.getSusheSno());
        List<Person> personList = personMapper.selectList(personWrapper);

        return personList;
    }
    public int updatePerson(String sno,String name,String floor ) {
    	QueryWrapper<Sushe> susheWrapper = new QueryWrapper<>();
        susheWrapper.eq("sushe_sno", sno);
        susheWrapper.eq("sushe_floor", floor);
        Sushe sushe = susheMapper.selectOne(susheWrapper);
        QueryWrapper<Person> personWrapper = new QueryWrapper<>();
        personWrapper.eq("person_sno", sushe.getSusheSno());
        Person person = personMapper.selectOne(personWrapper);
        person.setPersonName(name);
        int num = personMapper.updateById(person);
        return num;
    }
    public int insertPerson(String id, String name,String floor) {
        QueryWrapper<Sushe> susheWrapper = new QueryWrapper<>();
        susheWrapper.eq("sushe_floor", floor);
        Sushe sushe = susheMapper.selectOne(susheWrapper);

        Person person = new Person();
        person.setPersonId(id);
        person.setPersonName(name);
        person.setPersonSno(sushe.getSusheSno());
        int num = personMapper.insert(person);
        return num;
    }

}
